#pragma once

#ifndef _CCONSOLE_H_
#define _CCONSOLE_H_

#include "structs.h"

class CSemaphore;
class CWindowClass;
template<class T,class D>class T2List;

class CConsoleText
{
public:
	CConsoleText()
	{
		text = NULL;
		timeStampText = NULL;
		consoleAttribute = 0;
	}

	~CConsoleText()
	{
		if (text!=NULL)
			delete text;

		if (timeStampText != NULL)
			delete timeStampText;
	}

	char* text;
	char* timeStampText;
	int consoleAttribute;
};

class CConsole 
{	
private:
	static CWindowClass* outputWindow;

	//CConsole unlinked prints
	static CSemaphore* bufferCountSemaphore; 

	//CConsole writer semaphore
	static CSemaphore* bufferMutex; 
	//Reader needs no protection

	//A T1List (without key) would be better for this, maybe write a queue template?
	static T2List<CConsoleText*, CConsoleText*>* textBuffer;
public:
	CConsole::CConsole();
	CConsole::~CConsole();

	static void CConsole::init(void); 

	static void CConsole::outTime(char* buf, ...);
	static void CConsole::outTime(int color, char* buf ,... );
	static void CConsole::outErr(char* buf, ...);
	static void CConsole::outHr();
	static void CConsole::outHead(char* buf, ...);
	static void CConsole::outPlain(char* buf ,... );
	static void CConsole::outPlain(int color, char* buf ,... );
	static int  CConsole::recv(struct UDPdata * UDPcomm, struct Settings * s);
	//Debug Output
	static void CConsole::outDeb(char* buf, ...);
	//Debug Output that will only be displayed in debug builds
	static void CConsole::outDebOnly(char* buf, ...);
	//Get the generic output window
	static CWindowClass* getOutputWindow();

	//CConsole unlinked prints
	static DWORD WINAPI ConsolePrinter(LPVOID lpParam); 

	static void pushToQueue(CConsoleText* textObject);
};
#endif
